﻿using System;
using System.Collections.Generic;
using System.Text;
using ECC_EXT_Entity;
using NHibernate;
using NHibernate.Criterion;

namespace ECC_EXT_DAO.Dao
{
    public class MailContentDetailsDao:DaoBase
    {
        public void Remove(MailContentDetailsEntity _mailContentDetailEntity)
        {
            using (ISession session = this.SessionFactory.OpenSession())
            {
                session.BeginTransaction();
                session.Delete(_mailContentDetailEntity);
                session.Transaction.Commit();
            }
        }

        public void SaveOrUpdate(MailContentDetailsEntity _mailContentDetailEntity)
        {
            using (ISession session = this.SessionFactory.OpenSession())
            {
                    session.BeginTransaction();
                    session.SaveOrUpdate(_mailContentDetailEntity);
                    session.Transaction.Commit();
                
            }
        }

        public IList<MailContentDetailsEntity> Search(MailContentDetailsEntity _mailContentDetailEntity)
        {
            using (ISession session = this.SessionFactory.OpenSession())
            {
                ICriteria criteria =
                    session.CreateCriteria<MailContentDetailsEntity>();
                criteria.Add(Restrictions.Eq("EmailContentKeyID", _mailContentDetailEntity.EmailContentKeyID.ToUpper()));
                criteria.Add(Restrictions.Eq("Type", _mailContentDetailEntity.Type));
                return
                criteria.List<MailContentDetailsEntity>();
            }
        }
    }
}
